package com.levy.contronller.javase.designModel.iterator;

import java.util.Iterator;
import java.util.List;

/**
 *  隐藏容器内部的实现细节
 *  对其中的对象进行遍历访问
 *  1.访问容器内部的对象
 *  2.按顺序访问
 * Created by levy on 2018/8/1.
 */
public class MainClass {

    public static void main(String[] args) {
        BookList bookList = new BookList();
        Book book1 = new Book();
        book1.setIsbn("12312312");
        book1.setName("fdsfdf");
        Book book2 = new Book();
        book2.setIsbn("4234234");
        book2.setName("bvcvbvb");
        bookList.addBook(book1);
        bookList.addBook(book2);

//        while (bookList.hasNext()){
//            Book next = bookList.getNext();
//            System.out.println(next);
//        }

//        List<Book> bookList1 = bookList.getBookList();
//        for (Book book:bookList1){
//            System.out.println(book);
//        }
        Iterator iterator = bookList.getIterator();
        while (iterator.hasNext()){
            Book book = (Book) iterator.next();
            System.out.println(book);
        }
    }

}
